Ext.ns("crs.grid");

crs.grid.AlterationFormReviewGridPanel = Ext.extend(Ext.grid.EditorGridPanel, {

	/* begin of fields initialization */
	autoHeight : true,
	review_url : 'review_reviewAlteration.do',
	default_url : 'review_alterationsPendingReview.do',
	defaultProxy : '',
	pageSize : 15,
	closable : true,
	params : '',
	root : 'listCopyrightAlteration',
	totalProperty : 'pagination.totalCount',
	title : '待审核著作权变更或补充',
	detailWindow : {},
	detailForm : {},
	viewConfig : {
		deferEmptyText : false,
		emptyText : '没有可显示数据',
		forceFit : true
	},
	params : {},
	defaultProxy : {},
	fields : ['id', 'softFullName', 'sqrname', 'sqremail', 'applyTime',
			'copyrighter', 'originalRegType', 'originalRegNumber',
			'originalChangeNumber', 'applyingType', 'items', 'beforeContent',
			'afterContent'],
	columns : [{
				header : 'id',
				hidden : true,
				dataIndex : 'id'
			}, {
				header : '软件名称/版本',
				dataIndex : 'softFullName'
			}, {
				header : '申请人名',
				dataIndex : 'sqrname'
			}, {
				header : 'E-mail',
				dataIndex : 'sqremail'
			}, {
				header : '申请时间',
				dataIndex : 'applyTime'
			}],
	sm : new Ext.grid.RowSelectionModel({
				singleSelect : true
			}),
	initComponent : function() {
		this.buildProxies();
		this.initDetailForm();
		this.params = this.buildParams();
		this.store = this.buildStore();
		// this.columns = this.buildColumns();
		this.tbar = this.buildTbar();
		this.bbar = this.buildBbar();
		crs.grid.AlterationFormReviewGridPanel.superclass.initComponent
				.call(this);

		this.store.load(this.params);
	},
	initDetailForm : function() {
		this.detailForm = new Ext.form.FormPanel({
					frame : true,
					title : '详细信息',
					labelAlign : 'right',
					labelStyle : 'font-weight:bold;',
					labelWidth : 100,
					width : 700,
					/* 'items','beforeContent','afterContent' */
					items : [{
								layout : 'column',
								items : [{ // column #1
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '著作权人',
												name : 'copyrighter',
												disabled : true,
												anchor : '80%'

											}, {
												xtype : 'textfield',
												fieldLabel : '原登记类别',
												disabled : true,
												name : 'originalRegType',
												anchor : '80%'

											}, {
												xtype : 'textfield',
												fieldLabel : '原变更/补充登记证明编号',
												disabled : true,
												name : 'originalChangeNumber',
												anchor : '80%'

											}]
										// close items for first column
								}, {
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textfield',
												fieldLabel : '软件名称及版本号',
												name : 'softFullName',
												disabled : true,
												anchor : '80%'

											}, {
												xtype : 'textfield',
												fieldLabel : '原登记号',
												disabled : true,
												name : 'originalRegNumber',
												anchor : '80%'

											}, {
												xtype : 'textfield',
												fieldLabel : '申请时间',
												disabled : true,
												name : 'applyTime',
												anchor : '80%'

											}]
										// close items for second column
									}]
							}, {
								layout : 'form',
								items : [{
											xtype : 'textfield',
											fieldLabel : '变更项/补充项',
											disabled : true,
											name : 'items',
											anchor : '80%'

										}]
							},// 变更项内容
							{
								layout : 'column',
								items : [{ // column #1
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textarea',
												fieldLabel : '变更/补充前内容',
												name : 'beforeContent',
												disabled : true,
												anchor : '80%'

											}]
										// close items for first column
								}, {
									columnWidth : .5,
									layout : 'form',
									items : [{
												xtype : 'textarea',
												fieldLabel : '变更/补充后内容',
												name : 'afterContent',
												disabled : true,
												anchor : '80%'
											}]
										// close items for second column
									}]
							}]
				});

		this.detailWindow = new Ext.Window({
					frame : true,
					plain : true,
					modal : true,
					resizable : false,
					title : '详细信息',
					buttonAlign : "right",
					closeAction : "hide",
					closable : true,
					bodyStyle : "padding:4px",
					width : 700,
					autoHeight : true,
					layout : "form",
					items : [this.detailForm],
					buttons : [{
								text : "审核通过",
								handler : this.doReview,
								scope : this
							}, {
								text : "审核不通过",
								handler : this.doRefuse,
								scope : this
							}, {
								text : "取消",
								handler : function() {
									this.detailWindow.hide();
								},
								scope : this
							}]
				});
	},
	buildTbar : function() {
		return new Ext.Toolbar({
					items : ['-', {
								text : '详细信息',
								handler : this.showDetail,
								scope : this
							}, '-']
				});
	},
	/* end of components appending to this panel */
	buildStore : function() {

		return new Ext.data.Store({
					proxy : this.defaultProxy,
					reader : new Ext.data.JsonReader({
								root : this.root,
								totalProperty : this.totalProperty,
								fields : this.fields
							})
				});

	},

	buildProxies : function() {

		this.defaultProxy = new Ext.data.HttpProxy({
					url : this.default_url,
					method : 'post'
				});
	},
	buildBbar : function() {
		return new Ext.PagingToolbar({
					store : this.store,
					pageSize : this.pageSize,
					displayInfo : true
				});
	},
	buildParams : function() {
		var dataPost = {};
		dataPost.params = {};
		dataPost.params.start = 0;
		dataPost.params.limit = this.pageSize;
		return dataPost;
	},

	/* begin of handler implementation */
	showDetail : function(){
		this.detailForm.getForm().reset();
		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}
		window.open('calter_preReview.do?copyrightAlteration.id=' + this.selModel.getSelections()[0].id);

		/*this.detailWindow.show();

		var selRec = this.selModel.getSelections()[0];
		this.detailForm.getForm().loadRecord(selRec);*/
	},
	doRefuse : function() {
		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}

		this.el.mask("审核中...", 'x-mask-loading');

		Ext.Ajax.request({
					url : this.review_url,
					params : {
						// mapping to field named 'msisdn' of
						// mobileUserSearchAction at the backend
						'copyrightAlteration.id' : this.selModel
								.getSelections()[0].id,
						'copyrightAlteration.state' : 4

					},
					success : function(resp) {
						var rp = Ext.decode(resp.responseText);
						this.el.unmask();
						this.detailWindow.hide();
						if (rp.success == true) {
							Ext.MessageBox.alert('提示', '审核不通过!');
							this.store.load(this.params);
						} else if (rp.success == false) {
							Ext.MessageBox.alert('错误', '错误信息:' + rp.message);
						}
					},
					scope : this

				});
	},
	doReview : function() {

		if (this.selModel.getSelections().length < 1) {
			Ext.Msg.alert('提示', '请选择一项!');
			return;
		}

		this.el.mask("审核中...", 'x-mask-loading');

		Ext.Ajax.request({
					url : this.review_url,
					params : {
						// mapping to field named 'msisdn' of
						// mobileUserSearchAction at the backend
						'copyrightAlteration.id' : this.selModel
								.getSelections()[0].id,
						'copyrightAlteration.state' : 2

					},
					success : function(resp) {
						var rp = Ext.decode(resp.responseText);
						this.el.unmask();
						this.detailWindow.hide();
						if (rp.success == true) {
							this.store.load(this.params);
						} else if (rp.success == false) {
							Ext.MessageBox.alert('错误', '错误信息:' + rp.message);
						}
					},
					scope : this

				});
	}
		/* end of handler implementation */
	});

Ext.reg("alter_review_grid", crs.grid.AlterationFormReviewGridPanel);